<?php
if ( 'POST' != $_SERVER['REQUEST_METHOD'] ) {
	header('Allow: POST');
	header('HTTP/1.1 405 Method Not Allowed');
	header('Content-Type: text/plain');
	exit;
}

/** Sets up the WordPress Environment. */
require( dirname(__FILE__) . '/wordpress/wp-load.php' );

nocache_headers();

$defaults = array(
	'show_option_all' => '', 'show_option_none' => __('No categories'),
	'orderby' => 'name', 'order' => 'ASC',
	'show_last_update' => 0, 'style' => 'list',
	'show_count' => 0, 'hide_empty' => 1,
	'use_desc_for_title' => 1, 'child_of' => 0,
	'feed' => '', 'feed_type' => '',
	'feed_image' => '', 'exclude' => '',
	'exclude_tree' => '', 'current_category' => 0,
	'hierarchical' => true, 'title_li' => __( 'Categories' ),
	'echo' => 1, 'depth' => 0,
	'taxonomy' => 'category'
);

$r = wp_parse_args( $args, $defaults );

if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] )
	$r['pad_counts'] = true;

if ( isset( $r['show_date'] ) )
	$r['include_last_update_time'] = $r['show_date'];

if ( true == $r['hierarchical'] ) {
	$r['exclude_tree'] = $r['exclude'];
	$r['exclude'] = '';
}

if ( !isset( $r['class'] ) )
	$r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy'];

extract( $r );

if ( !taxonomy_exists($taxonomy) )
	return false;

$categories = get_categories( $r );

$output = '';

if ( empty( $categories ) ) {
	if ( ! empty( $show_option_none ) ) {
		if ( 'list' == $style )
			$output .= '<li>' . $show_option_none . '</li>';
		else
			$output .= $show_option_none;
	}
} else {
	if( !empty( $show_option_all ) )
		if ( 'list' == $style )
			$output .= '<li><a href="' .  get_bloginfo( 'url' )  . '">' . $show_option_all . '</a></li>';
		else
			$output .= '<a href="' .  get_bloginfo( 'url' )  . '">' . $show_option_all . '</a>';

	if ( empty( $r['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) {
		$current_term_object = get_queried_object();
		if ( $r['taxonomy'] == $current_term_object->taxonomy )
			$r['current_category'] = get_queried_object_id();
	}

	if ( $hierarchical )
		$depth = $r['depth'];
	else
		$depth = -1; // Flat.

	$output .= walk_category_tree( $categories, $depth, $r );
}

$output = apply_filters( 'wp_list_categories', $output, $args );

echo $output;
?>